package Farsail::Mock::DBI;

use DBI;
use Test::MockObject;
use Farsail::DBI;

my $object = bless({}, "Farsail::DBI");
my $cur_sql;
my $TRUE = sub { 1 };
my $FALSE = sub { 0 };
my $UNDEF = sub { undef };
my $EMPTY_ARRAY = sub { [] };
my $EMPTY_HASH = sub { {} };
my $NIL = sub { };

Test::MockObject->fake_module(
    'Farsail::DBI',
    connect =>  sub {
        return $object;
    },
    disconnect => $TRUE,
    errstr => sub {
        return "DBI error at '$cur_sql'";
    },
    prepare => sub {
        $cur_sql = shift || "";
        return $object;
    },
    prepare_cached => sub {
        $cur_sql = shift || "";
        return $object;
    },
    commit => $TRUE,
    bind_columns => $TRUE,
    bind_params => $TRUE,
    do => sub {
        $cur_sql = shift || "";
        return 1;
    },
    execute => $TRUE,
    finish => $TRUE,
    selectall_arrayref => $EMPTY_ARRAY,
    selectall_hashref => $EMPTY_HASH,
    fetchall_arrayref => $EMPTY_ARRAY,
    fetchrow_arrayref => $UNDEF,
    fetchall_hashref => $EMPTY_HASH,
    fetchrow_hashref => $UNDEF,
    fetchrow_array => $NIL,
    fetchrow => $NIL,
    fetch => $NIL,
    pg_getcopydata => $FALSE,
    pg_putcopydata => $TRUE,
    pg_endcopy => $TRUE,
    rows => $FALSE,
);
    
1;
